
Page({
    data: {
      id: 0, // 楼盘id
      propertyDetail: {}, // 楼盘详情
    },
    onLoad(t) {
      // getApp().page.onLoad(this, t);
      this.setData({
        id: t.id
      })
    },
    onReady() {},
    onShow() {
      this.getDetail();
    },
    onHide() {},
    onUnload() {},
    onPullDownRefresh() {},
    onReachBottom() {},
    onShareAppMessage() {},
    openMap() { // 打开地图
      wx.openLocation({
        latitude: Number(this.data.propertyDetail.latitude) || 22.746613678570018, //纬度，范围为-90~90，负数表示南纬,
        longitude: Number(this.data.propertyDetail.longitude) || 111.60096863287353, //经度，范围为-180~180，负数表示西经,
        scale: 15, //缩放比例，范围5~18,
        name: this.data.propertyDetail.name, //位置名,
        address: this.data.propertyDetail.houseAddress, //地址的详细说明,
        success: res => {}
      });
    },
    toPage(e) { // 页面跳转
      let target = e.currentTarget.dataset;
      if (target.url) {
        wx.navigateTo({ url: target.url });
      } else {
        console.warn('Not Page Url')
      }
    },
    // -----------------------------------
    getDetail() { // 获取详情
      let params = {id: this.data.id};
      if (getApp().globalData.userInfo && getApp().globalData.userInfo.memberId) {
        params.memberId = Number(getApp().globalData.userInfo.memberId)
      }
      getApp().api.getHouseDetail(params).then(res => {
        this.setData({
          propertyDetail: res.data,
          reservationData: JSON.stringify([{id: res.data.id, name: res.data.name}])
        })
        wx.setStorageSync('_propertyDetail', res.data);
      })
    },
    putCollect() { // 收藏、取消收藏
      if (!getApp().globalData.userInfo || !getApp().globalData.userInfo.memberId) {
        this.needLogin({type: 'navigateTo'});
        return false;
      }
      getApp().api.putCollect({
        houseId: Number(this.data.id),
        memberId: Number(getApp().globalData.userInfo.memberId),
        type: this.data.propertyDetail.iscollect ? 0 : 1
      }).then(res => {
        if (res.code == 200) {
          let up = 'propertyDetail.iscollect';
          this.setData({
            [up]: this.data.propertyDetail.iscollect ? 0 : 1
          })
        }
      })
    },
    needLogin() {}
  })
